using System;
using AtDevice;

namespace GtkControls
{
    
    public partial class PhoneBookNewEntryWindow : Gtk.Window
    {
        private IPhoneBook _phonebook;

        /// <summary>
        /// Construct new window for adding an entry to the active phone book.
        /// </summary>
        /// <param name="phonebook">The phonebook in which to create the new entry</param>
        public PhoneBookNewEntryWindow(IPhoneBook phonebook) : 
                base(Gtk.WindowType.Toplevel)
        {
            _phonebook = phonebook;
            this.Build();
        }

        protected virtual void OnOkButtonClicked (object sender, System.EventArgs e)
        {
            PhoneBookEntry entry = new PhoneBookEntry()
            {
                Index = _phonebook.GetFreeIndex(),
                MobileNumber = mobileNumberEntry.Text,
                Name = nameEntry.Text,
                OfficeNumber = officeEntry.Text,
                HomeNumber = homeNumberEntry.Text,
                Email = emailEntry.Text,
                Remarks = remarksEntry.Buffer.Text
            };
            _phonebook.AddEntry(entry);
            this.Destroy();
        }

        protected virtual void OnCancelButtonClicked (object sender, System.EventArgs e)
        {
            this.Destroy();
        }
    }
}
